package org.algorithm.熊猫.树;

import org.algorithm.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jzx
 * @date 2022/5/30
 * @desc {https://leetcode.cn/problems/binary-tree-inorder-traversal/}
 */
public class $5月31二叉树的中序遍历 {

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        //递归算法
         preorder(root, res);
         return res;
    }

    private void preorder(TreeNode root, List<Integer> res) {
        if (root == null) {
            return;
        }
        preorder(root.left, res);
        res.add(root.val);
        preorder(root.right, res);
    }
}
